package com.bq.server.base;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 创建时使用的字段
 *
 * @author: ChenSH
 * @date: Create by in 08:21 2019-09-18
 */
@Data
@EqualsAndHashCode(callSuper = true)
public abstract class IdEntity<T extends IdEntity<T>> extends DomainObject<T> {

    /**
     * 主键
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    public IdEntity(Long id) {
        this.id = id;
    }

    public IdEntity() {
    }

    protected IdEntity(IdEntityBuilder<T, ?, ?> b) {
        this.id = b.id;
    }


    public abstract static class IdEntityBuilder<T extends IdEntity<T>, C extends IdEntity<T>, B extends IdEntityBuilder<T, C, B>> {
        private Long id;

        public IdEntityBuilder() {
        }

        protected abstract B self();

        public abstract C build();

        public B id(Long id) {
            this.id = id;
            return this.self();
        }

        public String toString() {
            return "IdEntity.IdEntityBuilder(id=" + this.id + ")";
        }
    }
}
